'''索引的文件插入的需要的associate文件中'''

# 定义文件路径
file1_path = 'E:\data\data_0905/room/associate.txt'  # 替换为文件1的路径
file2_path = 'n1.txt'  # 替换为文件2的路径

# 读取文件1的内容
with open(file1_path, 'r') as f1:
    lines_file1 = f1.readlines()

# 读取文件2的内容
with open(file2_path, 'r') as f2:
    lines_file2 = f2.readlines()

# 合并文件内容
combined_lines = lines_file1 + lines_file2

# 去除重复行，并按第一个字段（时间戳）排序
unique_sorted_lines = sorted(set(combined_lines), key=lambda x: float(x.split()[0]))

# 将结果写入文件1
with open(file1_path, 'w') as f1:
    f1.writelines(unique_sorted_lines)

print(f"文件2的内容已插入文件1，并按第一个字段排序。")
